<template>
  <view class="detail-container">

    <!-- 主要内容区域 -->
    <scroll-view class="content" scroll-y>
      <!-- 封面图片 -->
      <view class="cover-image-container">
        <image 
          :src="url('ib', currentIndex, 'jpg')" 
          mode="aspectFill" 
          class="cover-image"
        />
        <view class="image-overlay">
          <text class="image-title">{{ currentItem?.name }}</text>
        </view>
      </view>

      <!-- 内容详情 -->
      <view class="detail-content">
        <!-- 详细描述 -->
        <view class="description-section">
          <text class="description-text">{{ currentItem?.txt }}</text>
        </view>

        <!-- 相关推荐 -->
        <view class="related-section">
          <text class="section-title">相关推荐</text>
          <view class="related-list">
            <view 
              v-for="(item, index) in relatedItems" 
              :key="index"
              class="related-item"
              @tap="navigateToDetail(index)"
            >
              <image 
                :src="url('ib', index, 'jpg')" 
                mode="aspectFill" 
                class="related-image"
              />
              <text class="related-title">{{ item.name }}</text>
            </view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script setup>
import { ref, onMounted, computed } from 'vue';
import { useCounterStore } from '@/stores/counter';

const url = $url;
const store = useCounterStore();

// 获取当前项目索引和数据
const currentIndex = ref(0);
const currentItem = computed(() => store.cultureArray[currentIndex.value]);

// 相关推荐数据
const relatedItems = computed(() => {
  return store.cultureArray.filter((_, index) => index !== currentIndex.value);
});

// 返回上一页
const goBack = () => {
  uni.navigateBack();
};

// 跳转到其他详情
const navigateToDetail = (index) => {
  uni.redirectTo({
    url: `/pages/culture/detail?index=${index}`
  });
};

// 页面加载时获取参数
onMounted(() => {
  const pages = getCurrentPages();
  const currentPage = pages[pages.length - 1];
  const index = currentPage.options.index || 0;
  currentIndex.value = Number(index);
});
</script>

<style scoped>


.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 90rpx;

  display: flex;
  align-items: center;
  padding: 0 30rpx;
  z-index: 100;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

.back-button {
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.title {
  flex: 1;
  text-align: center;
  font-size: 32rpx;
  font-weight: bold;
  margin-right: 60rpx;
}

.content {

  height: calc(100vh - 90rpx);
}

.cover-image-container {
  position: relative;
  width: 100%;
  height: 400rpx;
}

.cover-image {
  width: 100%;
  height: 100%;
}

.image-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 40rpx 30rpx;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
}

.image-title {
  color: #fff;
  font-size: 36rpx;
  font-weight: bold;
}

.detail-content {
  padding: 30rpx;
  background: #fff;
  border-radius: 30rpx;
  margin-top: -30rpx;
  position: relative;
  min-height: 800rpx;
}

.description-section {
  margin: 30rpx 0;
}

.description-text {
  font-size: 28rpx;
  color: #333;
  line-height: 1.8;
}


.related-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20rpx;
}

.related-item {
  background: #fff;
  border-radius: 12rpx;
  overflow: hidden;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

.related-image {
  width: 100%;
  height: 200rpx;
  object-fit: cover;
}

.related-title {
  font-size: 28rpx;
  color: #333;
  padding: 16rpx;
  display: block;
}
</style> 